/*******************************************************************************
 ** Name: object.cpp                                                          **
 ** Description:                                                              **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved 2-clause BSD License                **
 **                                                                           **
 **  Copyright (c) 2009-2010 Barry "Gian" James  <bjames@munixos.net>         **
 **  All rights reserved.                                                     **
 **                                                                           **
 **  Redistribution and use in source and binary forms, with or without       **
 **  modification, are permitted provided that the following conditions are   **
 **  met:                                                                     **
 **                                                                           **
 **  * Redistributions of source code must retain the above copyright notice, **
 **    this list of conditions and the following disclaimer.                  **
 **  * Redistributions in binary form must reproduce the above copyright      **
 **    notice, this list of conditions and the following disclaimer in the    **
 **    documentation and/or other materials provided with the distribution.   **
 **                                                                           **
 **  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS      **
 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED **
 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           **
 ** PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT        **
 ** HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    **
 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED  **
 ** TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR    **
 ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    **
 ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      **
 ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        **
 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              **
 **                                                                           **
 ******************************************************************************/
// Modified $Date: 2011-10-22 02:09:07 +0000 (Sat, 22 Oct 2011) $ by $Author: gian.james $
#define _object_cpp_ID    "$Id: object.cpp 146 2011-10-22 02:09:07Z gian.james $"

#include <boost/lexical_cast.hpp>
#include <cstring>
#include "object.hpp"



// Moved from using ID to using UUID for uniqueness tests 5.12.11 -gian
bool operator < (WorldObject a, WorldObject b)
{
//    return a.ID() < b.ID();
	return a.UUID() < b.UUID();
}

// Not sure if this should compare object ID's or string compare names?
bool operator == (WorldObject a, WorldObject b)
{
//    return a.ID() == b.ID();
	return a.UUID() == b.UUID();
}

/////////////////////////////////[ WorldObject
boost::uuids::uuid
WorldObject::StringToUUID(const std::string & u)
{
	return boost::lexical_cast<boost::uuids::uuid>(u);
}

bool
WorldObject::IsAdjective(const std::string & s)
{
	std::list<std::string>::const_iterator	i;
	for (i = adj.begin(); i != adj.end(); i++)
	{
		if ((*i) == s)
			return true;
	}
	return false;
}

//void
//WorldObject::AddAttribute(const std::string & a, const std::string & v)
//{
//	attr[a] = v;
//}


//constructor
WorldObject::WorldObject(OType t, std::string n)
{
    otype = t;
	name = n;
    aka = NULL;
    weight = WEIGHT_UNLIFTABLE;
	slots = 1;
	
    boost::uuids::random_generator gen;
    boost::uuids::uuid u = gen();
    uuid = UUID2String(u);
    carriedBy = complexity = craftedBy = 0;
    detectDC = disableDC = dmgSave = durabilityCurr = 0;
    durabilityDecay = 0.0;
    durabilityMax = powerRating = slots = stackAmount = 0;
    inRoom = false;
    x = y = xpReward = 0;
    tier = TierGrade::I;
}

WorldObject::WorldObject(void)
{
    otype = OType::Unknown;
    aka = NULL;
    weight = WEIGHT_UNLIFTABLE;
	name = "<UNKNOWN>";

    boost::uuids::random_generator gen;
    boost::uuids::uuid u = gen();
    uuid = UUID2String(u);
    carriedBy = complexity = craftedBy = 0;
    detectDC = disableDC = dmgSave = durabilityCurr = 0;
    durabilityDecay = 0.0;
    durabilityMax = powerRating = slots = stackAmount = 0;
    inRoom = false;
    x = y = xpReward = 0;
    tier = TierGrade::I;
}

//destructor
WorldObject::~WorldObject(void)
{

}
